home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-11-13 | 3.0 KB | 124 lines | [TEXT/PJMM] |
- unit DemoInit;
-
- { WASTE DEMO PROJECT: }
- { Initialization & Finalization Routines }
-
- { Copyright © 1993-1994 Merzwaren }
- { All Rights Reserved }
-
- interface
- uses
- DemoIntf;
-
- function Initialize: OSErr;
- procedure Finalize;
-
- implementation
- uses
- DemoEvents, DemoMenus, DemoWindows, DemoPictures, DemoDrags, TextServices;
-
- function Initialize: OSErr;
-
- const
- kMinSystemVersion = $700;
- kScrapThreshold = 4 * 1024;
-
- var
- response: LongInt;
- scrapResult: LongInt;
-
- procedure CheckErr (err: OSErr);
- begin
- if (err <> noErr) then
- begin
- Initialize := err;
- ErrorAlert(err);
- Exit(Initialize);
- end;
- end; { CheckErr }
-
- begin
- Initialize := noErr;
-
- { expand the zone to its maximum size }
- MaxApplZone;
-
- { allocate some extra master pointer blocks }
- MoreMasters;
- MoreMasters;
- MoreMasters;
- MoreMasters;
-
- { initialize the Toolbox }
- InitGraf(@thePort);
- InitFonts;
- InitWindows;
- InitMenus;
- TEInit;
- InitDialogs(nil);
- InitCursor;
- FlushEvents(everyEvent, 0);
-
- { if desk scrap is too large, unload it }
- if (InfoScrap^.scrapSize > kScrapThreshold) then
- scrapResult := UnloadScrap;
-
- { make sure system software version is 7.0 or newer }
- if (Gestalt(gestaltSystemVersion, response) <> noErr) | (response < kMinSystemVersion) then
- begin
- SetCursor(arrow);
- response := Alert(kAlertNeedSys7, nil);
- Initialize := -1;
- Exit(Initialize);
- end;
-
- { determine whether Color QuickDraw is available }
- gHasColorQD := (Gestalt(gestaltQuickDrawVersion, response) = noErr) & (response >= gestalt8BitQD);
-
- { determine whether the Drag Manager is available }
- gHasDragAndDrop := (Gestalt(gestaltDragMgrAttr, response) = noErr) & BTST(response, gestaltDragMgrPresent);
-
- { determine whether the Text Services Manager is available }
- gHasTextServices := (Gestalt(gestaltTSMgrVersion, response) = noErr);
-
- { register this application with the TSM }
- if (gHasTextServices) then
- CheckErr(InitTSMAwareApplication);
-
- { install default drag handlers }
- if (gHasDragAndDrop) then
- begin
- CheckErr(InstallTrackingHandler(@MyTrackingHandler, nil, nil));
- CheckErr(InstallReceiveHandler(@MyReceiveHandler, nil, nil));
- end;
-
- { install the handlers for PICT objects }
- CheckErr(WEInstallObjectHandler(kTypePicture, weNewHandler, @HandleNewPicture));
- CheckErr(WEInstallObjectHandler(kTypePicture, weDisposeHandler, @HandleDisposePicture));
- CheckErr(WEInstallObjectHandler(kTypePicture, weDrawHandler, @HandleDrawPicture));
-
- { perform other initialization chores }
- CheckErr(InitializeEvents);
- CheckErr(InitializeMenus);
-
- end; { Initialize }
-
- procedure Finalize;
- begin
-
- { remove drag handlers }
- if (gHasDragAndDrop) then
- begin
- if (RemoveTrackingHandler(@MyTrackingHandler, nil) <> noErr) then
- ;
- if (RemoveReceiveHandler(@MyReceiveHandler, nil) <> noErr) then
- ;
- end;
-
- { notify text services that we're closing down }
- if (gHasTextServices) then
- if (CloseTSMAwareApplication <> noErr) then
- ;
- end; { Finalize }
-
- end.